﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyUAMS.BLL;
using MyUAMS.DAL;

public partial class UserWork_UpdateAsset : System.Web.UI.Page
{
    WorkServer assetSrv = new WorkServer();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            WBind();
        }
    }
    protected void WBind()
    {

        if (Request.QueryString["Aid"] == null)
        {
            username.Text = "发生错误了！";
        }
        else
        {
            int assestId = int.Parse(Request.QueryString["Aid"]);
            var assest = assetSrv.GetAssetByAid(assestId);

            var types = assetSrv.GetAllCategory();
            foreach(var category in types)
            {
                TypeId.Items.Add(new ListItem(category.Tname,category.Tid.ToString()));
            }

            txtName.Text = assest.Aname;
            TypeId.SelectedValue=assest.Tid.ToString();
            AmountUnit.Text = assest.Unit.ToString();
            txtCperson.Text = assest.Cperson.ToString();
            txtTelephone.Text = assest.Telephone.ToString();
            txtDpartment.Text=assest.Department.ToString();
            txtDtelephone.Text=assest.DTelephone.ToString();
            AssetDescribe.Text=assest.Describe.ToString();
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["Aid"] != null)
        {

            int aid = int.Parse(Request.QueryString["Aid"]);
            assetSrv.Update(aid,int.Parse(TypeId.SelectedValue) ,txtName.Text.Trim(),AmountUnit.Text.Trim(),
                AssetDescribe.Text.Trim(), txtCperson.Text.Trim(), decimal.Parse(txtTelephone.Text.Trim()),
                txtDpartment.Text.Trim(), decimal.Parse(txtDtelephone.Text.Trim()));
           
            ////重定向
            Response.Redirect("MyWork.aspx");
        }
        else
        {
            username.Text = "出现问题辣";
        }
    }

    protected void return_Click(object sender, EventArgs e)
    {
        Response.Redirect("MyWork.aspx");
    }
}